/*
 * Copyright (C) 2011  John Lawrence thegordo.john at gmail.com
 * Licensed under GPLv3 or later. see http://www.gnu.org/copyleft/gpl.html
 */

package org.jklawrencefam.server.smtp.command;

import org.jklawrencefam.annotation.smtp.SmtpCommandMarker;
import org.jklawrencefam.server.smtp.SmtpCode;
import org.jklawrencefam.server.smtp.state.StateParameters;

/**
 * User: John Lawrence
 * Date: 5/24/11
 * Time: 6:22 AM
 */
@SmtpCommandMarker(Helo.NAME)
public class Helo extends SmtpCommand {
    public static final String NAME = "HELO";

    private String domain;

    protected Helo(String CommandString) {
        super(CommandString);
        if (argumentString != null) {
            domain = argumentString.split(" ")[0];
        }
    }

    @Override
    public String getReplyMessage() {
        return composeMessage(SmtpCode.OK, "Hello", domain);
    }

    @Override
    protected boolean isValid() {
        return domain != null;
    }

    @Override
    public void doProcessInternal() {
        state.setParameter(StateParameters.ClientDomain, domain);
    }
}
